import pandas as pd
import numpy as np 

left = pd.DataFrame({'姓名':['zs','ls'],'age':[20,18]}) 
print(left) 

right = pd.DataFrame({'姓名':['zs','ls'],'性别':['男','女']})  
print(right)  

# merge() - 连接
print(pd.merge(left,right,on='姓名'))


# groupby() - 分组
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
                'foo', 'bar', 'foo', 'foo'],
             'B': ['one', 'one', 'two', 'three',
                     'two', 'two', 'one', 'three'],
                 'C': np.random.randn(8),
                 'D': np.random.randn(8)})

print(df) 

# agg(函数)  - 聚合（集合->值）
la = df.groupby(by='A').agg(sum) 
print(la) 

lb = df.groupby(by='B').aggregate(max) 
print(lb) 

# # apply(函数) 
# lc = df.groupby(by='B').apply(max)     
# print(lc) 

lc = df.groupby(by='B').sum()
print(lc)
